﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace webtelmail
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void match(String page)
        {   try
            {
                string phone = @"^1[34578]\\d{9}$";            
                string email = @"\w[-\w.+]*@([A-Za-z0-9][-A-Za-z0-9]+\.)+[A-Za-z]{2,14}";

                foreach (Match match in Regex.Matches(page, email))
                    MessageBox.Show(match.Value);             //弹窗显示匹配成功信息

                foreach (Match match in Regex.Matches(page, phone))
                    MessageBox.Show(match.Value);
            }
            catch(Exception ee)
            {
                MessageBox.Show(ee.Message);
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                string url = textBox1.Text;
                WebClient client = new WebClient();
                byte[] pageData = client.DownloadData(url);
                string pageHtml = Encoding.UTF8.GetString(pageData);//获取网页内的资源
                match(pageHtml);//进行正则表达式匹配
            }
            catch(Exception fe)
            { MessageBox.Show(fe.Message); }

        }
    }
}
